﻿package org.xhs.report.common.model
{
    import baidu.wenku.common.*;
    import flash.events.*;
    import flash.external.*;

    public class SeriesModel extends EventDispatcher
    {
        protected var _hasData:Boolean = false;
        protected var _isOpen:Boolean = false;
        protected var _seriesLength:int = 0;
        protected var _dataArray:Array;
        public static const DATA_SUCCEED:String = "DATA_SUCCEED";
        public static const OPEN_PANEL:String = "OPEN_PANEL";
        public static const CLOSE_PANEL:String = "CLOSE_PANEL";

        public function SeriesModel(param1:IEventDispatcher = null)
        {
            super(param1);
            return;
        }// end function

        public function loadData() : void
        {
            var _loc_1:Array = null;
            var _loc_2:Object = null;
            var _loc_3:int = 0;
            var _loc_4:int = 0;
            this._hasData = false;
            if (ExternalInterface.available)
            {
                try
                {
                    _loc_1 = ExternalInterface.call(JSInterface.AS_SERIES) as Array;
                }
                catch (e:Error)
                {
                }
            }
            if (_loc_1 && _loc_1.length)
            {
                this._dataArray = [];
                this._seriesLength = _loc_1.length;
                _loc_3 = 0;
                _loc_4 = this._seriesLength;
                while (_loc_3 < _loc_4)
                {
                    
                    _loc_2 = new Object();
                    _loc_2.id = _loc_3;
                    _loc_2.docType = _loc_1[_loc_3].doctype ? (_loc_1[_loc_3].doctype) : ("doc");
                    _loc_2.title = _loc_1[_loc_3].title ? (_loc_1[_loc_3].title) : ("百度文库");
                    _loc_2.link = _loc_1[_loc_3].docurl ? (_loc_1[_loc_3].docurl) : ("http://wenku.baidu.com");
                    this._dataArray.push(_loc_2);
                    _loc_3++;
                }
                this._hasData = true;
                dispatchEvent(new Event(DATA_SUCCEED));
            }
            return;
        }// end function

        public function get hasData() : Boolean
        {
            return this._hasData;
        }// end function

        public function get dataArray() : Array
        {
            return this._dataArray;
        }// end function

        public function get seriesLength() : int
        {
            return this._seriesLength;
        }// end function

        public function get isOpen() : Boolean
        {
            return this._isOpen;
        }// end function

        public function set isOpen(param1:Boolean) : void
        {
            this._isOpen = param1;
            if (this._isOpen)
            {
                if (this._hasData)
                {
                    dispatchEvent(new Event(OPEN_PANEL));
                }
                else
                {
                    this.loadData();
                }
            }
            else
            {
                dispatchEvent(new Event(CLOSE_PANEL));
            }
            return;
        }// end function

    }
}
